package com.hclc.entity.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @Author: hef
 * 地域级别
 * @Date: Create in 4:16 下午 2020/8/9
 */
public enum HierarchyEnum implements IEnum<Integer> {


    COUNTRY(0, "国家"),


    PROVINCE(1, "省"),


    CITY(2, "市"),


    COUNTY(3, "区");



    @JsonValue
    @EnumValue
    private final int code;


    private final String desc;
    HierarchyEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }
    @Override
    public Integer getValue() {
        return code;
    }
    public String getDesc(){return desc;}
    public static HierarchyEnum find(String desc ) throws IllegalArgumentException{
        for (HierarchyEnum model : HierarchyEnum.values()) {
            if (model.getDesc().equals(desc)) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }
    @JsonCreator
    public static HierarchyEnum find(int code ) throws IllegalArgumentException{
        for (HierarchyEnum model : HierarchyEnum.values()) {
            if (model.getValue() == code) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }
}
